package com.alibaba.controller;

import com.alibaba.domain.User;
import com.alibaba.feignclient.UserFeignClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping()
public class PayController {
    // 注入feign接口

    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/getById/{id}")
    @HystrixCommand(fallbackMethod = "fallbackMethod") // 自动降级 标记为熔断，自动托底
    public User getById(@PathVariable Long id){
        return userFeignClient.getUserById(id);
    }

    public User fallbackMethod(@PathVariable Long id){
        return new User(-1L,"服务熔断触发","用户服务不可用");
    }
}
